package main

import (
	"context"
	"fmt"
	"github.com/apache/rocketmq-client-go/v2"
	"github.com/apache/rocketmq-client-go/v2/consumer"
	"github.com/apache/rocketmq-client-go/v2/primitive"
	"os"
)

func main() {

	sig := make(chan os.Signal)
	var c, _ = rocketmq.NewPushConsumer(
		consumer.WithGroupName("simpleGroup"),
		consumer.WithNsResolver(primitive.NewPassthroughResolver([]string{"127.0.0.1:9876"})),
	)

	err := c.Start()
	if err != nil {
		panic("Start failed")
		os.Exit(-1)
	}

	err = c.Subscribe("asyncTopic", consumer.MessageSelector{}, func(ctx context.Context, msg ...*primitive.MessageExt) (consumer.ConsumeResult, error) {

		for i := range msg {
			fmt.Printf("$$$$$$$ %v", string(msg[i].Message.Body))
		}

		return consumer.ConsumeSuccess, nil
	})
	if err != nil {
		panic("subceive failed")
	}

	<-sig
	err = c.Shutdown()
	if err != nil {
		panic("shut down fail")
	}
}
